package com.platform.demo;

import com.platform.api.Job;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Controller {

  @GetMapping("v1/platform/job/start")
  public void startJob() throws ClassNotFoundException {
    var jobWrapper = PlatformContext.getJobWrapper("1");
    var job = jobWrapper.getJob();
    if (job == null) {
      Class<Job> c = (Class<Job>) jobWrapper.getClassLoader().loadClass(jobWrapper.getJobClass());
      var iJob = jobWrapper.getContext().getBean(c);
      jobWrapper.setJob(iJob);
    }
    jobWrapper.getJob().run(null);

  }
}
